package cn.ivicar.iov.controller;

import cn.ivicar.iov.entity.BackInfo;
import cn.ivicar.iov.service.impl.ExcelToMysqlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

//@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@RestController
@Transactional
public class GetFlowInfoListZipController {

    @Autowired
    private ExcelToMysqlService excelToMysqlService;

    @PutMapping("/putfile")
    public BackInfo putFile(MultipartFile fileZip, HttpServletRequest request) throws IOException {
        return excelToMysqlService.excelTomysql(fileZip,request);
    }

    @PutMapping("/haha")
    public BackInfo putFile() throws IOException {
        BackInfo b = new BackInfo();
        b.setMessage("哈哈哈");
        b.setStatus(1);
        return b;
    }

    public static String getExtensionName(String filename) {
        if ((filename != null) && (filename.length() > 0)) {
            int dot = filename.lastIndexOf('.');
            if ((dot >-1) && (dot < (filename.length() - 1))) {
                return filename.substring(dot + 1);
            }
        }
        return filename;
    }


//    public static void main(String[] args) {
//        SpringApplication.run(GetFlowInfoListZipController.class,args);
//
//    }
}
